package com.map.ui;



import android.os.Bundle;
import android.preference.PreferenceActivity;


import android.view.ViewGroup;
import android.widget.*;
import android.content.*;

import android.os.*;
import android.preference.*;
import android.preference.Preference.*;

import com.map.view.PreferenceView;
import com.xl.game.math.*;
import com.xl.game.tool.SharedPreferencesUtil;

import android.content.pm.*;
import android.provider.BaseColumns;

public class SetActivity extends BaseActivity
{

	
	EditTextPreference blackSize;
	CheckBoxPreference isSave;
	CheckBoxPreference isAlphaDraw;
	ListPreference  screen;

	ListPreference  theme;
	
	
//	@Override
//	public boolean onPreferenceChange(Preference p1, Object p2)
//	{
//		if(p1==blackSize)
//		{
//			BaseConfig.blackSize=Str.atoi((String)p2);
//			toast(""+p2,0);
//		}
//		else if(p1==isSave)
//		{
//			BaseConfig.isSaveLastFile=(boolean)p2;
//		}
//		else if(p1 == isAlphaDraw){
//			BaseConfig.isAlphaDraw = (boolean)p2;
//		}
//		else if(p1==screen)
//		{
//			String temp=(String)p2;
//			BaseConfig.screen=(String)p2;
//
//		}
//		else if(p1==theme)
//		{
//			String themeText=(String)p2;
//			BaseConfig.themeText = themeText;
//		}
//		return true;
//	}

	xlApplication application;

	protected void onCreate(Bundle savedInstanceState) 
	{
		super.onCreate(savedInstanceState);
		ScrollView scrollView = new ScrollView(this);
		PreferenceView preferenceView = new PreferenceView(this);
		scrollView.addView(preferenceView, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);


		preferenceView.addEdit("默认图块大小","设置编辑器默认图块大小","com.map.ui.BaseConfig.blackSize");
		preferenceView.addEdit("默认项目文件夹","设置文件tmx打开的默认路径", "com.map.ui.BaseConfig.fileDir");
		preferenceView.addCheck("记住最后打开的文件","当编辑器启动时，自动打开没有关闭的文件","com.map.ui.BaseConfig.isSaveLastFile");
		preferenceView.addCheck("半透明显示图层","将当前图层以外的图层半透明显示","com.map.ui.BaseConfig.isAlphaDraw");
		preferenceView.addCheck("按钮模式","显示旧版本模式","com.map.ui.BaseConfig.oldMode");
		preferenceView.addList("屏幕方向","设置屏幕显示方向",new String[]{"跟随系统","横屏","竖屏"},"com.map.ui.BaseConfig.screen");
		preferenceView.addList("主题","设置APP主题色",new String[]{"白色","黑色"},"com.map.ui.BaseConfig.themeText");
		setContentView(scrollView);
		getSupportActionBar().setDisplayHomeAsUpEnabled(true);
		//	exb.write("setting");
		String key="setting";
//	if(BaseConfig. themeText.equals("白色"))
//	{
//	setTheme(R.style.AppTheme_Light);
//	}
//	else
//	{
//	setTheme(R.style.AppTheme);
//	}

//	if(BaseConfig.screen.equals("横屏"))
//	{
//	BaseConfig. orientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
//	}
//	else if(BaseConfig.screen.equals("竖屏"))
//	{
//	BaseConfig. orientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
//	}
//	else
//	{
//	BaseConfig. orientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
//	}
//	setRequestedOrientation(BaseConfig.orientation);
//
		

	
/*
		this.addPreferencesFromResource(R.xml.setting);

		//CheckBoxPreference组件 

		 blackSize=(EditTextPreference)findPreference("blackSize");
		 isSave = (CheckBoxPreference)findPreference("isSaveLastFile");
		isAlphaDraw = (CheckBoxPreference)findPreference("isAlphaDraw");
		 screen=(ListPreference)findPreference("screen");
		
		  theme=(ListPreference)findPreference("theme");
		
		blackSize.setOnPreferenceChangeListener(this);
		isSave.setOnPreferenceChangeListener(this);
		screen.setOnPreferenceChangeListener(this);
		theme.setOnPreferenceChangeListener(this);
		*/
		




	}

	@Override
	protected void onDestroy() {
		super.onDestroy();
		SharedPreferencesUtil sharedPreferences = //getSharedPreferences("settings",Context.MODE_PRIVATE);
				new SharedPreferencesUtil(this);
		sharedPreferences.setBoolean("isSaveLastFile",BaseConfig.isSaveLastFile);
		sharedPreferences.setBoolean("isAlphaDraw",BaseConfig.isAlphaDraw);
		sharedPreferences.getString("theme",BaseConfig.themeText);


		sharedPreferences.setString("blackSize",""+BaseConfig.blackSize);
		sharedPreferences.setString("filePath",BaseConfig.fileDir);


		sharedPreferences.setString("screen",BaseConfig.screen);
		sharedPreferences.setString("theme",BaseConfig.themeText);
	}

	void toast(String text, int type)
	{
		Toast.makeText(this,text,type).show();
	}
}


